
<%@ page language="java" isELIgnored="false" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ include file="/include/header.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><s:i18n name="menus"><s:text name="fareInquiry"></s:text></s:i18n></title>
<link href="<%=request.getContextPath() %>/fare/css/base.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/datePicker/WdatePicker.js"></script>
<script src="${baseURL}/js/layer/layer.min.js?v=1.8.0" type="text/javascript"></script>
<link href="<%=request.getContextPath() %>/fare/css/base.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/jsFile/multiblepicker.js"></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/json2.js'></script>

<link rev="stylesheet" media="all" href="<%=request.getContextPath() %>/fare/css/form_style.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="<%=request.getContextPath()%>/jsFile/fdc.js"></script>
 	<link href='<%=request.getContextPath()%>/fare/js/cityquery/cityquery.css' rel="stylesheet" type="text/css" />
	<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/citylist.js'></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/querycity.js'></script> 
<!-- 圆角文本框 -->
<link href="<%=request.getContextPath() %>/fare/css/htc/htc.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/grid.css"/>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/public.css"/>
<script type="text/javascript"
	src="<%=request.getContextPath() %>/jsFile/FDCCrawl/js/FDCCrawl.js">
</script>
<script type="text/javascript"
	src="<%=request.getContextPath() %>/jsFile/wait/js/wait.js"></script>
<style type="text/css">
        .l-case-title{font-weight:bold; margin-top:20px;margin-bottom:20px;}
        .l-taskbar {display: none;}
        .form_list td{
        	text-align: center;
        }
</style>

	<script type="text/javascript">

	
function formatTime(time){
	if(time==null || time.length<12)return null;
	return time.substring(8, 10)+":"+time.substring(10,12);
}
function showTransit(row){
	var transitLength = row.transit.length;
	var transitInfo = '';
	for ( var i = 0; i < transitLength; i++) {
		transitInfo += row.transit[i].transitName 
		+ '('+ row.transit[i].flightTyte +')'+' '+ row.transit[i].fromAir+'('+row.transit[i].startTime+')'+ ' - '+row.transit[i].toAir +'('+row.transit[i].endTime+')'+ '\n';
	}
	return transitInfo;
}

function createCabin(subCabinName,cabinNo,cabinType,cabinRebate,cabinServer,lever,price,productName){
	var tempCabin = new Object();
	tempCabin.subCabinName = subCabinName;
	tempCabin.cabinNo = cabinNo;
	tempCabin.cabinType = cabinType;
	tempCabin.cabinRebate = cabinRebate;
	tempCabin.cabinServer = cabinServer;
	tempCabin.lever = lever;
	tempCabin.price = price;
	tempCabin.productName = productName;
	return tempCabin;
	
}

function createReturnTrip(carrierFullName,carrierKey,carrierName ,endTime ,
							flightDate ,flightNo ,fromAir ,fromCity ,fromCityName ,startTime ,toAir ,
       								  toCity,toCityName ,totalPrice  ){
	var tempReturnTrip = new Object();
	tempReturnTrip.carrierFullName = carrierFullName;
	tempReturnTrip.carrierKey = carrierKey;
	tempReturnTrip.carrierName = carrierName;
	tempReturnTrip.endTime = endTime;
	tempReturnTrip.flightDate = flightDate;
	tempReturnTrip.flightNo = flightNo;
	tempReturnTrip.fromAir = fromAir;
	tempReturnTrip.fromCity = fromCity;
	tempReturnTrip.fromCityName = fromCityName;
	tempReturnTrip.startTime = startTime;
	tempReturnTrip.toAir = toAir;
	tempReturnTrip.toCity = toCity;
	tempReturnTrip.toCityName = toCityName;
	tempReturnTrip.totalPrice = totalPrice;
	return tempReturnTrip;
}

function showMuchInfo(id,standardPrice,returnTripId,carrierFullName,flightId){
	//alert(returnTripString);
	//var row = null;
	var dialogWidth = null;
	 var rowListName = new Array();
	 var rowListType = new Array();
	 var rowList = new Array();
	 var returnRowList = new Array();
	var rowArray = $(id).val().split(":");
	
	var nameArray = rowArray[0];
	var typeArray = rowArray[1];
	if(nameArray == "" && typeArray ==""){
		return;
	}
	
	var nameStringArray = null;
	var typeStringArray = null;
    var returnStringArray = null;	 
		 nameStringArray = nameArray.split("#");

		 if (typeof(nameStringArray) != "undefined" && nameStringArray!= "") { 
			 for(var j=0;j<nameStringArray.length;j++){
					var temp = nameStringArray[j].split("_");
						var cabinTemp = createCabin(temp[0],temp[1],temp[2],temp[3],temp[4],temp[5],temp[6],temp[7]);
						rowListName.push(cabinTemp);

			}
		 	 rowList.push(rowListName);
		 } 
		
		if (typeof (typeArray) != "undefined" && typeArray!="" ) {
				typeStringArray = typeArray.split("#");
				for ( var j = 0; j < typeStringArray.length; j++) {
					var temp = typeStringArray[j].split("_");
					var cabinTemp = createCabin(temp[0], temp[1], temp[2],
							temp[3], temp[4], temp[5], temp[6], temp[7]);
					rowListType.push(cabinTemp);
				}
				rowList.push(rowListType);
		}
			//获得返程舱位字符串
			var returnCabinString = $(returnTripId).val();
			var cabinArray = returnCabinString.split("*");
			var totalCabinList = new Array();
			for ( var i = 0; i < cabinArray.length; i++) {
				//i name:type
				var cabinList = new Array();
				var cabinStr = cabinArray[i].split(":");
				if (cabinStr.length > 0) {
					if (typeof cabinStr[0] != "undefined" && cabinStr[0] != ''
							&& cabinStr[0].indexOf("#")) {
						var nameTemp = cabinStr[0].split("#");
						for ( var j = 0; j < nameTemp.length; j++) {
							var temp = nameTemp[i].split("_");
							var cabinTemp = createCabin(temp[0], temp[1],
									temp[2], temp[3], temp[4], temp[5],
									temp[6], temp[7]);
							cabinList.push(cabinTemp);
						}
					}
					if (typeof cabinStr[1] != "undefined" && cabinStr[1] != ''
							&& cabinStr[1].indexOf("#")) {
						var typeTemp = cabinStr[1].split("#");
						for ( var k = 0; k < typeTemp.length; k++) {
							var temp = typeTemp[i].split("_");
							var cabinTemp = createCabin(temp[0], temp[1],
									temp[2], temp[3], temp[4], temp[5],
									temp[6], temp[7]);
							cabinList.push(cabinTemp);
						}
					}
					if (cabinList.length > 0) {
						totalCabinList.push(cabinList);
					}
				}

			}

			//组织去程舱位
			var info = '';
			var cabinsLength = rowList.length;
			var tableStr = '<table  class=\"form_list\" style=\"text-align: center;margin-left: -3px;margin-right: 7px;\">';
			if(rowList[0].length<=3){
				tableStr = '<table  class=\"form_list\" style=\"text-align: center;margin-left: -3px;margin-right: 7px; width:300px;\">';
			}
			if (cabinsLength && cabinsLength > 0) {
				//tableStr += '<td class=\'line\'>舱位名称</td>'+'<td class=\'line\'>编号</td>'+'<td class=\'line\'>价格</td>'+'<td class=\'line\'>折扣</td>'+'<td class=\'line\'>类型</td>'+'<td class=\'line\'>服务</td>';
				tableStr += '<tr>';
				tableStr += '<td style=\"text-align: center;\" class=\'line\'><s:i18n name="forms"><s:text name="forms.type"></s:text></s:i18n></td>';
				//如果是海航
				if ($('#carrier').val() == '20004') {
					for ( var j = 0; j < cabinsLength; j++) {
						if (rowList[j] != null) {
							for ( var i = 0; i < rowList[i].length; i++) {
								if (rowList[j][i].productName != null) {
									tableStr += '<td style=\"text-align: center;\" class=\'line\'>'
											+ rowList[j][i].productName
											+ '</td>';
								} else if (rowList[j][i].productName == null
										&& rowList[j][0].cabinType != null) {
									tableStr += '<td style=\"text-align: center;\" class=\'line\'>'
											+ rowList[j][0].cabinType + '</td>';
								} else {
									tableStr += '<td style=\"text-align: center;\" class=\'line\'></td>';
								}

							}

						} else {
							tableStr += '<td style=\"text-align: center;\" class=\'line\'>'
									+ '' + '</td>';
						}
					}
				} else {
					//for ( var j = 0; j < cabinsLength; j++) {
						//alert(rowList[j].length);
						if (rowList[0] != null && rowList[0].length > 0) {
							 for ( var i = 0; i < rowList[0].length; i++) { 
								if (rowList[0][i].cabinType != ""
										&& typeof (rowList[0][i].cabinType) != "undefined") {
									var length = rowList[0].length;
										if(rowList[0][i].cabinType == "null"){
											tableStr += '<td style=\"text-align: center;\" class=\'line\'>'
											+ "" + '</td>';
										}else{
											tableStr += '<td style=\"text-align: center;\" class=\'line\'>'
											+ rowList[0][i].cabinType + '</td>';
										}
								} else {
								/* 	if (nameArray.indexOf("#") != -1) {
										var length = nameStringArray.length;
	
										tableStr += '<td style=\"text-align: center;\" colspan='+length+' class=\'line\'></td>';
									} */
									var length = rowList[0].length;
									tableStr += '<td style=\"text-align: center;\" class=\'line\'></td>';
								}
							 }

						}
					//}
				}

				tableStr += '</tr>';
				tableStr += '<tr>';

				tableStr += '<td style=\"text-align: center;\" class=\'line\'><s:i18n name="forms"><s:text name="forms.cabin"></s:text></s:i18n></td>';

				//for ( var j = 0; j < cabinsLength; j++) {
					if (rowList[0] != null) {
						for ( var i = 0; i < rowList[0].length; i++) {

							if (rowList[0][i].subCabinName != null
									&& rowList[0][i].subCabinName != "") {
								tableStr += '<td style=\"text-align: center;\" class=\'line\'>'
										+ (rowList[0][i].subCabinName == 'null' ? '' :  rowList[0][i].subCabinName)
												+ '</td>';
										
							} else if (rowList[0][i].cabinType == ""
									|| typeof (rowList[0][i].cabinType) == "undefined") {

							} else {
								tableStr += '<td style=\"text-align: center;\" class=\'line\'></td>';
							}

						}

					}
			//	}

				tableStr += '</tr>';

				tableStr += '<tr>';

				tableStr += '<td style=\"text-align: center;\" class=\'line\'><s:i18n name="forms"><s:text name="forms.price"></s:text></s:i18n></td>';
			//	for ( var j = 0; j < cabinsLength; j++) {
					if (rowList[0] != null) {
						for ( var i = 0; i < rowList[0].length; i++) {
							if (rowList[0][i].price != null
									&& typeof (rowList[0][i].price) != "undefined"
									&& rowList[0][i].price != "") {
								tableStr += '<td style=\"text-align: center;\" class=\'line\'>'
										+ rowList[0][i].price + '</td>';
							}

						}

					}
			//	}
				tableStr += '</tr>';

				tableStr += '<tr>';

				tableStr += '<td style=\"text-align: center;\" class=\'line\'><s:i18n name="forms"><s:text name="forms.discount"></s:text></s:i18n></td>';
				dialogWidth +=120;
			//	for ( var j = 0; j < cabinsLength; j++) {
					if (rowList[0] != null) {
						for ( var i = 0; i < rowList[0].length; i++) {
							dialogWidth += 60;
							if (rowList[0][i].price != null) {
								var lowerPrice = parseFloat(rowList[0][i].price);
								if (standardPrice == '1') {
									var rebate = '<s:i18n name="forms"><s:text name="forms.unknown"></s:text></s:i18n>';
									tableStr += '<td style=\"text-align: center;\" class=\'line\'>'
											+ rebate + '</td>';
								} else {
									var rebate = lowerPrice
											/ parseFloat(standardPrice) * 10;
									tableStr += '<td style=\"text-align: center;\" class=\'line\'>'
											+ toDecimal(rebate) + '</td>';
								}

							}

						}
					}
				//}
				tableStr += '</tr>';

				tableStr += '</table>';
			}
			//组织返程舱位 totalCabinList
			if (totalCabinList && totalCabinList.length > 0) {

				for ( var i = 0; i < totalCabinList.length; i++) {
					//每一个返程航班
					var cabinList = totalCabinList[i];
					//生成第一行
					tableStr += '<table  class=\"form_list\" style=\"text-align: center;margin-left: -3px;margin-right: 7px;\">';
					tableStr += '<tr>';
					tableStr += '<td style=\"text-align: center;\" class=\'line\'><s:i18n name="forms"><s:text name="forms.type"></s:text></s:i18n></td>';
					for ( var j = 0; j < cabinList.length; j++) {
						tableStr += '<td style=\"text-align: center;\" colspan='+1+' class=\'line\'>'
								+ cabinList[j].cabinType + '</td>';
					}

					tableStr += '</tr>';
					//生成第二行
					tableStr += '<tr>';
					tableStr += '<td style=\"text-align: center;\" class=\'line\'><s:i18n name="forms"><s:text name="forms.cabin"></s:text></s:i18n></td>';
					for ( var j = 0; j < cabinList.length; j++) {
						tableStr += '<td style=\"text-align: center;\" colspan='+1+' class=\'line\'>'
								+ cabinList[j].cabinName + '</td>';
					}

					tableStr += '</tr>';
					//生成第三行
					tableStr += '<tr>';
					tableStr += '<td style=\"text-align: center;\" class=\'line\'><s:i18n name="forms"><s:text name="forms.price"></s:text></s:i18n></td>';
					for ( var j = 0; j < cabinList.length; j++) {
						tableStr += '<td style=\"text-align: center;\" colspan='+1+' class=\'line\'>'
								+ cabinList[j].price + '</td>';
					}

					tableStr += '</tr>';
					//生成第四行
					tableStr += '<tr>';
					tableStr += '<td style=\"text-align: center;\" class=\'line\'><s:i18n name="forms"><s:text name="forms.discount"></s:text></s:i18n></td>';
					for ( var j = 0; j < cabinList.length; j++) {
						var lowerPrice = parseFloat(cabinList[j].price);
						if (standardPrice == '1') {
							var rebate = '<s:i18n name="forms"><s:text name="forms.unknown"></s:text></s:i18n>';
							tableStr += '<td style=\"text-align: center;\" class=\'line\'>'
									+ rebate + '</td>';
						} else {
							var rebate = lowerPrice / parseFloat(standardPrice)
									* 10;
							tableStr += '<td style=\"text-align: center;\" class=\'line\'>'
									+ toDecimal(rebate) + '</td>';
						}

					}
					tableStr += '</tr>';
					tableStr += '</table>';
				}

			}

			if (cabinsLength && cabinsLength > 0) {
				$.layer({
				    type: 1,
				    title: "<div style='float:left;'>"+carrierFullName+flightId+'<s:i18n name="forms"><s:text name="forms.cabinInformation"></s:text></s:i18n>'+"</div>",
				    area: ['auto', '160px'],
				   // offset: [($(window).height()- 200)/2 + 'px', ''],
				    shade: [0],
				    page: {
				        html: tableStr
				    }/* , success: function(){
				        layer.shift('left'); //左边动画弹出
				    } */
				});
				
				
				/* $.ligerDialog.open({
					height : 200,
					content : tableStr,
					width : dialogWidth,
					title : '<s:i18n name="forms"><s:text name="forms.cabinInformation"></s:text></s:i18n>'
				}); */
			}

			// 将ligerDialog自带的任务栏隐藏不显示
			$(".l-taskbar").hide();
			$(".l-taskbar-tasks").hide();

		}


		function toDecimal(x) {
			var f = parseFloat(x);
			if (isNaN(f)) {
				return;
			}
			f = Math.round(x * 100) / 10;
			return f + "%";
		}

		//连接到航班走势对比
		function hrefHBZSDB(airCompany, airNum, from, to, channels) {
			if ($.trim(from) == "北京") {
				from = "北京(PEK)";
			}
			if ($.trim(to) == "北京") {
				to = "北京(PEK)";
			}

			var url = "airCompanyTrendContrastFlightAction!toAnalyseJSP.action";

			//以小窗口的形式打开网页

			var w_w = 1100;
			var w_h = 550;
			var iTop = (window.screen.availHeight - 30 - w_h) / 2; //获得窗口的垂直位置;
			var iLeft = (window.screen.availWidth - 10 - w_w) / 2; //获得窗口的水平位置;
			var obj = {
				href_airLine : airNum,
				href_airCompanyName : airCompany,
				href_depCity : from,
				href_arrCity : to,
				href_channels : channels,
				href_state : "href"

			};
			window
					.showModalDialog(
							url,
							obj,
							'dialogHeight='
									+ w_h
									+ 'px;dialogWidth='
									+ w_w
									+ 'px;dialogLeft='
									+ iLeft
									+ 'px;dialogTop='
									+ iTop
									+ 'px;status=no;scroll=yes;resizable=no;help=no,center=yes');

		}

		/* function showm(sid){

		 var which = document.getElementById("lite" + sid);
		 var imgmenu = document.getElementById("ling" + sid);
		 if (which.style.display == "none"){
		 document.getElementById("lite" + sid).style.display="";
		 }
		 else{
		 document.getElementById("lite" + sid).style.display="none";
		 }
		 }


		 */

		function currentDate() {
			var now = new Date();
			var year = now.getFullYear();
			var month = now.getMonth() + 1;
			var day = now.getDate();

			var today = year + "-";
			if (month < 10)
				today += "0";
			today += month + "-";
			if (day < 10)
				today += "0";
			today += day;
			return (today);
		}

		$(function() {

			/* if ("${showButton}" == "true") {

				$("#crawlrealtime").show();
			} else {
				$('#crawlrealtime').hide();
			} */
			$('#depCity').querycity({
				'data' : citysFlight,
				'tabs' : labelFromcity
			});
			$('#arrCity').querycity({
				'data' : citysFlight,
				'tabs' : labelFromcity
			});

			if ($('#grapDate').val() == '') {
				$('#grapDate').val(currentDate());
			}
			if ($('#depTime').val() == '') {
				$('#depTime').val(currentDate());
			}

			$("#depCity").css({
				color : "black"
			});
			$("#arrCity").css({
				color : "black"
			});

		})

		function loadAndDisplayData(grid, url) {
			$("#table2").empty();
			  FDCWait.show(); 
			var chk_value = [];
			$('input[name="vo.checkbox"]:checked').each(function() {
				chk_value.push($(this).val());
			});
			$("#channel").attr("action", url);
			var currentCarrier = $("#carrier").val().split("_")[0];
			var channelArr = [currentCarrier];
			$("input[name='sourceChannel']").each(function(){
				channelArr.push($(this).val());
			});
			if ($('#depCity').val() != '' && $('#arrCity').val()) {
				for ( var i = 0; i < channelArr.length; i++) {
					$("#checkboxToSend").val(chk_value.join(","));
					$("#channelKey").val(channelArr[i]);
					$.ajax({
						type : "POST",
						url : url,
						async : false,
						data : $("#channel").serialize(),
						success : function(jsonData) {
						//	$("#crawlrealtime").show();
							
							if (jsonData.jsonSize != '0') {
							
								createTable(jsonData.jsonString,
										jsonData.standardPrice);
							}

						}
					});
				}
				  FDCWait.hide(); 
			}
		}
		function createTable(jsonData, standardPrice) {
			
			for ( var i = 0; i < jsonData.length; i++) {
				var tableStr = '';
				rowIndex = i+1;
				data = jsonData[i];
				tableStr += "<tr>";
				tableStr += '<td class="line" style="text-align: center">'
						+ (i + 1) + '</td>';
				tableStr += '<td class="line" style="text-align: center;table-layout: fixed; word-wrap: break-word;ssss">'
						+ createFlightInfo(data) + '</td>';
				tableStr += '<td class="line" style="text-align: center">'
						+ data.flightBatchDate + '</td>';
				tableStr += '<td class="line" style="text-align: center">'
						+ data.grapDateStr + '</td>';
				tableStr += '<td class="line" style="text-align: center">'
						+ data.highPrice + '</td>';
				tableStr += '<td class="line" style="display: none;"> <input value="" type="text" id="data'+ (i + 1)+"_"+data.grabChannelNum + '"/></td>';
				tableStr += '<td class="line" style="display: none;"> <input value=""  type="text" id="returnTrip'+ (i + 1) +"_"+data.grabChannelNum + '"/></td>';
				tableStr += '<td class="line" style="display: none;"> <input value=""  type="text" id="dataReturnCabin'+ (i + 1) +"_"+data.grabChannelNum + '"/></td>';
				
				tableStr += '<td class="line" style="text-align: center">'
						+"<a href=\"javascript:void(0);\" onclick=\"showMuchInfo("+"data"+rowIndex+"_"+data.grabChannelNum+","+standardPrice+","+"dataReturnCabin"+rowIndex+"_"+data.grabChannelNum+",'"+data.grabChannel+"','"+data.flightId+"')\">"+data.lowerPrice+"</a>"
						+ '</td>';
				tableStr += '<td class="line" style="text-align: center">';
				if (data.tendency == -1) {
					tableStr += '<img style=\"padding: 4px;\" src=\"'
							+ '<%=request.getContextPath()%>/images/ico16/priority_0.gif'+'\"></img>';
				}else if(data.tendency == 0){
					tableStr +='<img style=\"padding: 4px;\" src=\"'+'<%=request.getContextPath()%>/images/ico16/ico-desktopzj.gif'+'\"></img>';
				}else if(data.tendency == 1){
					tableStr +='<img style=\"padding: 4px;\" src=\"'+'<%=request.getContextPath()%>/images/ico16/priority_1.gif'+'\"></img>';
				}
		tableStr += '</td>';
		tableStr += '<td class="line" style="text-align: center">'+data.grabChannel+'</td>';
		if(null==data.agentName || data.agentName=="null"){
			tableStr += '<td class="line" style="text-align: center"></td>';
			
		}else{
			tableStr += '<td class="line" style="text-align: center">'+data.agentName+'</td>';
		}
		
		tableStr += '</tr>';
		$("#table2").append(tableStr); 
		createCabinList(data,standardPrice,rowIndex);
	}
	var lineFlag = "<tr style=\"border-bottom-style:double;border-color:#CC33FF\"></tr>";
	$("#table2").append(lineFlag); 
	
}
function createCabinList(data,standardPrice,rowIndex){
	var cabinListString = "";
	var cabinStringWithName = "";
	var cabinStringWithType = "";
	var returnTripString = "";
	if(data.cabins.length>0){
		//for(var i=0;i<data.classifyCabins.length;i++){
		//	var list = data.classifyCabins[i];
			for(var j=0;j<data.cabins.length;j++){
				var cabinEntity = data.cabins[j];
				var price = cabinEntity.price;
				if(cabinEntity.subCabinName!= null && cabinEntity.subCabinName != ""){
					cabinStringWithName = cabinStringWithName+cabinEntity.subCabinName+"_"+cabinEntity.cabinNo+"_"+cabinEntity.cabinType+"_"+cabinEntity.cabinRebate+"_"+cabinEntity.cabinServer+"_"+cabinEntity.lever+"_"+price+"_"+cabinEntity.productName+"#";
				}
				if(cabinEntity.cabinType!= null && cabinEntity.cabinType != "")
				{	
				
					cabinStringWithType = cabinStringWithType+cabinEntity.subCabinName+"_"+cabinEntity.cabinNo+"_"+cabinEntity.cabinType+"_"+cabinEntity.cabinRebate+"_"+cabinEntity.cabinServer+"_"+cabinEntity.lever+"_"+price+"_"+cabinEntity.productName+"#";
				}
				
			}
			
	//	}
	}
	var returnCabinListString = "";
	var returnCabinStringWithName = "";
	var returnCabinStringWithType = "";

	if(data.returnPlaneInfo.length>0){
		
		for(var i = 0;i<data.returnPlaneInfo.length;i++){
			for(var j=0;j<data.returnPlaneInfo[i].cabins.length;j++){
				var cabinEntity = data.returnPlaneInfo[i].cabins[j];
				var price = cabinEntity.price;
				if(cabinEntity.subCabinName!= null && cabinEntity.subCabinName != ""){
					returnCabinStringWithName = returnCabinStringWithName+cabinEntity.subCabinName+"_"+cabinEntity.cabinNo+"_"+cabinEntity.cabinType+"_"+cabinEntity.cabinRebate+"_"+cabinEntity.cabinServer+"_"+cabinEntity.lever+"_"+price+"_"+cabinEntity.productName+"#";
				}
				if(cabinEntity.cabinType!= null && cabinEntity.cabinType != "")
				{	
				
					returnCabinStringWithType = returnCabinStringWithType+cabinEntity.subCabinName+"_"+cabinEntity.cabinNo+"_"+cabinEntity.cabinType+"_"+cabinEntity.cabinRebate+"_"+cabinEntity.cabinServer+"_"+cabinEntity.lever+"_"+price+"_"+cabinEntity.productName+"#";
				}
				
				
			}
		}
	}
	cabinListString = cabinStringWithName.substring(0,cabinStringWithName.length-1) + ":" + cabinStringWithType.substring(0,cabinStringWithType.length-1) ;
			
	$("#"+"data"+rowIndex+"_"+data.grabChannelNum ).val(cabinListString);
	$("#returnTrip"+rowIndex+"_"+data.grabChannelNum ).val(returnTripString);
	
	cabinListString = $("#"+"data"+rowIndex+"_"+data.grabChannelNum ).val();
	//alert($("#data1_20005").val()+" "+rowIndex +" "+ $("#"+"data"+rowIndex+"_"+data.grabChannelNum ).val());
	returnCabinListString = returnCabinListString.substring(0,returnCabinListString.length-1);
	$("#dataReturnCabin"+rowIndex+"_"+data.grabChannelNum).val(returnCabinListString);
	 /*  var aHtml = "<a href=\"javascript:void(0);\" onclick=\"showMuchInfo("+"data"+rowIndex+"_"+data.grabChannelNum+","+standardPrice+","+"dataReturnCabin"+rowIndex+"_"+data.grabChannelNum+")\">"+data.lowerPrice+"</a>";										
	return aHtml; */ 
}
function createFlightInfo(data){
	 /* var info = data.carrierFullName+"<a href=javascript:void(0) onclick=hrefHBZSDB('"+data.carrierFullName+"','"+data.flightId+"','"+data.fromCityName+"','"+data.toCityName+"','"+data.grabChannel+"')>("+data.flightId+")</a>"
		  +"  "+data.flightBatchStartTime+' - '+data.flightBatchEndTime +"  "+ data.fromCityName+' - '+data.toCityName; */
		  var info = data.carrierFullName+data.flightId
		  +"  "+data.flightStartHM+' - '+data.flightEndHM +"  "+ data.fromCityName+' - '+data.toCityName;
		 
	 if(data.transit.length > 0 ){
		 var transitHtml="";
		 for(var j = 0 ; j<data.transit.length;j++){
			 var transitPlane = data.transit[j];
			 transitHtml +=transitPlane.transitInfoDesc +'<br>';
		 }
		 
		 info += '<br>'+"<a href=\"javascript:void(0);\" onclick=\"showTransit('"+data.grabChannel+"','"+data.flightId+"','"+transitHtml+"')\">"+'<s:i18n name="forms"><s:text name="forms.transit"></s:text></s:i18n>'+"</a>";
		
		 
	 }
	 
	 
	 if(data.stopOverlist.length > 0){
		 for(var j=0;j<data.stopOverlist.length;j++){
			 var stopOverPlane = data.stopOverlist[j];
			 info += '<br>'
  				 + stopOverPlane.stopCity+"  <s:i18n name='forms'><s:text name='forms.arrivalTime'></s:text></s:i18n>:"+formatTime(stopOverPlane.arrTime)+"  <s:i18n name='forms'><s:text name='forms.departureTime'></s:text></s:i18n>:"+formatTime(stopOverPlane.leaveTime);
		 }
		
	 }
		 
	 if(data.returnPlaneInfo.length >0){
		 for(var j = 0;j<data.returnPlaneInfo.length ;j++){
			 var returnPlaneInfo = data.returnPlaneInfo[j];
			 info += '<br>'+returnPlaneInfo.carrierFullName+"("+
				returnPlaneInfo.flightId+")"+formatTime(returnPlaneInfo.flightBatchStartTime)+' - '+
				formatTime(returnPlaneInfo.flightBatchEndTime) +"  "+ returnPlaneInfo.fromCityName+' - '+returnPlaneInfo.toCityName;
			 
				
			 for(var k = 0 ;k<returnPlaneInfo.transit.length;k++){
				var transitPlane = returnPlaneInfo.transit[k];
				info += '<br>'
	   				 + transitPlane.carrierName+"("+transitPlane.flightNo+")"
                  +'   '+formatTime(transitPlane.startTime)+' - '+formatTime(transitPlane.endTime) +'  '+ transitPlane.fromAirPortName+' - '+transitPlane.toAirPortName + '<br>';
			 }
			 
			 for(var k = 0;k<returnPlaneInfo.stopOverlist.length;k++){
				 var  stopOverPlane = returnPlaneInfo.stopOverlist[k];
				 info += '<br>'
	   				 + stopOverPlane.stopCit+"  <s:i18n name='forms'><s:text name='forms.arrivalTime'></s:text></s:i18n>:"+formatTime(stopOverPlane.arrTime)+"  <s:i18n name='forms'><s:text name='forms.departureTime'></s:text></s:i18n>:"+formatTime(stopOverPlane.leaveTime);
			 }
			 
		 }
	 }
	 return info;
}

function showTransit(grabChannel,flightNo,html){
	//html="<table  class='form_list'  style='width:600px;'/>"+html;
	var bodyhtml="<table  class='form_list'  style='width:600px;'/>";
	var  arr=y = new Array();
	arr=html.split('<br>');
	for(var i=0;i<arr.length;i++){
		if(arr[i]!=""){
			bodyhtml=bodyhtml+"<tr><td class='line'>" +arr[i] +"</td></tr><br>";	
		}
	}
	bodyhtml+="</table>";
	$.layer({
	    type: 1,
	    title: "<div style='float:left;'>"+grabChannel+flightNo+"</div>",
	    area: ['auto', 'auto'],
	   // offset: [($(window).height()- 200)/2 + 'px', ''],
	    shade: [0],
	    page: {
	        html: bodyhtml
	    }/* , success: function(){
	        layer.shift('left'); //左边动画弹出
	    } */
	});
}

function changeAction(url){
	$('#channel').attr('action',url);
}


function getFlightNos(){
	var result = {"Total":2,"Rows":[{"flightNo":"CZ6158","fromCity":"PEK","toCity":"HAK","fromCityName":"北京","toCityName":"海口"},{"flightNo":"CZ6720","fromCity":"PEK","toCity":"HAK","fromCityName":"北京","toCityName":"海口"}]}
	var columns2 = [ { display: '航班选择', name: 'flightNo', align: 'center', width: 440, minWidth: 60 } ];
	var dep = $('#depCity').val();
	var arr = $('#arrCity').val();
	if(dep !='<s:i18n name="forms"><s:text name="forms.cnOrPingYing"></s:text></s:i18n>'&&dep&&arr !='<s:i18n name="forms"><s:text name="forms.cnOrPingYing"></s:text></s:i18n>'&&arr){
		registPicker('flightNos',"pageUtilAction!flightsOfLine.action",columns2,460,'flightNo'); 
	}
}

function checkForm(){
	if($('#depCity').val()=='<s:i18n name="forms"><s:text name="forms.cnOrPingYing"></s:text></s:i18n>' || $('#arrCity').val()=='<s:i18n name="forms"><s:text name="forms.cnOrPingYing"></s:text></s:i18n>'){
		alert('<s:i18n name="forms"><s:text name="forms.chooseRoutes"></s:text></s:i18n>');
	        return false;
	}
	
	if($('#depCity').val()==$('#arrCity').val()){
		alert('<s:i18n name="forms"><s:text name="forms.sameCity"></s:text></s:i18n>');
        return false;
	}
	if($('#depCity').val()==''||$('#arrCity').val()==''){
		alert('<s:i18n name="forms"><s:text name="forms.chooseRoutes"></s:text></s:i18n>');
        return false;
	}
	var depTime=$("#depTime").val();
	var grapDate=$("#grapDate").val();
	if(depTime==''||grapDate==''){
		alert('<s:i18n name="forms"><s:text name="forms.notDate"></s:text></s:i18n>');
        return false;
	}
	var isCheck=false;
	 $("input[name='vo.checkbox']").each(function() {
		if($(this).attr("checked")=='checked' || $(this).attr("checked")==true || $(this).attr("checked")=='true'){
			isCheck=true;
		}
	 });
	 if(!isCheck){
		 alert("<s:i18n name='forms'><s:text name='forms.chooseOne'></s:text></s:i18n>");
			return false;
	 }
	
	//自定义Time
	var timeFbegin=$("#timeFbegin").val();
	var timeTbegin=$("#timeTbegin").val();
	if(timeFbegin!=''||timeTbegin!=''){
		if(timeFbegin==""||timeTbegin==""){
			
			alert('自定义时间填写不完整!');
			return ;
		}
		if(parseInt(timeFbegin)>parseInt(timeTbegin)){
			alert('自定义结束时间不能小于开始时间');
			return false;
		} if(parseInt(timeFbegin)>24||parseInt(timeFbegin)<0){
			alert('自定义开始时间大于等于0小于24');
			return false;
		}
		if(parseInt(timeTbegin)>24||parseInt(timeTbegin)<0){
			alert('自定义结束时间大于等于0小于24');
			return false;
		}
	}
	
	if(!checkTime()){
		return false;
	}
	
	$("#beginDateAfterToday").val(parseInt($("#beginDateAfterToday").val()));
	
	
	$("#endDateAfterToday").val(parseInt($("#endDateAfterToday").val()));
	
	return true;
}
function checkTime(){
	var startTime = $("#depTime").val();  
    var start = new Date(startTime.replace("-", "/").replace("-", "/"));  
    var endTime = $("#grapDate").val();  
    var end = new Date(endTime.replace("-", "/").replace("-", "/")); 
    var time = start.getTime()-end.getTime();//获得毫秒数差
    if(time<0){
    	alert('<s:i18n name="forms"><s:text name="forms.grabDateEarlier"></s:text></s:i18n>');
        return false; 
    }
   /*  var days = Math.floor(time/(24*3600*1000));//计算相差日期
	    if(days>31){
			alert('航班出发日期过大与抓取时间差最多为30天!');
	        return false; 
		} */
	return true;
}
function checkJspForm(){

	if(!checkForm()){
		return false;
	}
	$("#inputDeptCitys").val(document.getElementById('depCity').value);
	$("#inputArrCityCodes").val(document.getElementById('arrCity').value);
	setTimeout(function(){loadAndDisplayData($('#channel'),'lowestPriceQueryAction!analyse.action');},1);
}


function reloadByCrawlRealTime(){
	//FDCWait.show();	
	 var url = 'lowestPriceQueryAction!crawlAllPlaneInfosByCompany.action'; 
	 loadAndDisplayData($('#channel'),url);
}
</script>
</head>

<body>
<%@ include file="/include/home/home_header.jsp" %>
<jsp:include page="/pages/system/feedback/feedback.jsp"></jsp:include>

<div class="main main_max minhgt450">
	<div class="sideBar">
	<div class="box">
		<div class="location"><s:i18n name="forms"><s:text name="forms.position"></s:text></s:i18n>： <s:i18n name="menus"><s:text name="fareInquiry"></s:text></s:i18n> &gt;  
		<s:i18n name="menus"><s:text name="search"></s:text></s:i18n></div>
		
	</div>
	</div>
<div class="form_table_tltle" ><s:i18n name="forms"><s:text name="forms.query"></s:text></s:i18n></div>
<form id="channel" name="channelForm" method="post" action="lowestPriceQueryAction!analyse.action">
	<input type="hidden" id="inputDeptCitys" name="inputDeptCitys" />
	<table cellSpacing=0 cellPadding=0 width="100%" border=0 class="form_table">
	
	    <TR>
	  	<TD height="26" class="left" style="text-align:left"><s:i18n name="forms"><s:text name="forms.airlines"></s:text></s:i18n>：</TD>
	  	<TD>

	  	   <select name="vo.carrier" style="width: 150px;" id="carrier">
							<c:choose>
								<c:when test="${sourceLists == null}">
								</c:when>
								<c:otherwise>
									<c:forEach var="o" items="${sourceLists}">
										<option value="${o.hbaseKey}_${o.carrierKey}" 
											<c:if test="${o.hbaseKey==vo.carrier}">selected='selected' </c:if> >${o.name}</option>
									</c:forEach>
								</c:otherwise>
							</c:choose>
						</select><font color="red">*</font>
	  	</TD>
	  	<TD class="left" style="text-align:left"></TD>
	  	<TD>
	  	 	<input type="hidden" id="channelKey" name="channelKey" />
	  	 	<c:forEach var="o" items="${channelsList}">
	  	 		<input type="hidden" name="sourceChannel" value="${o.hbaseKey}"/>
	  	 	</c:forEach>
	  	</TD>
	  </TR>
	  
	  <TR>
	    <TD width="120" height="26" class="left" style="text-align:left"><s:i18n name="forms"><s:text name="forms.trip"></s:text></s:i18n>：</TD>
	    <TD id="flight_Select">
	    <c:if test="${language=='en_US'}">
	    <jsp:include page="../inc/flightSelect_en_Us.jsp">
				<jsp:param value="${fromCity}" name="fromCity"/>
				<jsp:param value="${fromCityCode}" name="fromCityCode"/>
				<jsp:param value="${toCity}" name="toCity"/>
				<jsp:param value="${toCityCode}" name="toCityCode"/>
			</jsp:include>
	    </c:if>
	    <c:if test="${language=='zh_CN' or language=='other'}">
	   			 <jsp:include page="../inc/flightSelect.jsp">
				<jsp:param value="${fromCity}" name="fromCity"/>
				<jsp:param value="${fromCityCode}" name="fromCityCode"/>
				<jsp:param value="${toCity}" name="toCity"/>
				<jsp:param value="${toCityCode}" name="toCityCode"/>
				</jsp:include>
	    </c:if>
	   
	   			
		</TD>
	    <TD width="120" class="left" style="text-align:left">
	    	<s:i18n name="forms"><s:text name="forms.queryType"></s:text></s:i18n>：
	    </TD>
	    <TD>
	  		<input type="radio" name="vo.queryType" value="singleTrip" checked="checked"/><s:i18n name="forms"><s:text name="forms.oneWay"></s:text></s:i18n>&nbsp;&nbsp;&nbsp;
	  		<input type="radio" name="vo.queryType" value="doubleTrip" /><s:i18n name="forms"><s:text name="forms.roundTrip"></s:text></s:i18n>
		</TD>
	  </TR>
	  
	  
	  <TR>
	  	<TD height="26" class="left" style="text-align:left"><s:i18n name="forms"><s:text name="forms.flightDate"></s:text></s:i18n>：</TD>
	  	<TD>
	  <input name="vo.depTime" type="text" id="depTime" style="width:100px" value="${vo.depTime}"  
	  	  onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',lang:'<s:i18n name='forms'><s:text name='forms.locale'></s:text></s:i18n>'});" readonly="readonly">
	  		<font color="red">*</font>
	  	</TD>
	  	<TD class="left" style="text-align:left"><s:i18n name="forms"><s:text name="forms.returnDate"></s:text></s:i18n>：</TD>
	  	<TD>
	  		<input name="vo.returnDate" type="text" id="returnDate" style="width:100px" value="${vo.returnDate }"<%--  ${vo.returnDate} --%> 
	  	  onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',lang:'<s:i18n name='forms'><s:text name='forms.locale'></s:text></s:i18n>'});" readonly="readonly">
	  	</TD>
	  </TR>
	  <TR>
	  	<TD  height="26" class="left" style="text-align:left"><s:i18n name="forms"><s:text name="forms.grabDate"></s:text></s:i18n>：</TD>
	  	<TD>
	  	 <input name="vo.grapDate" type="text" id="grapDate" style="width:100px" value="${vo.grapDate}"   
	  	 onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',maxDate:'%y-%M-%d',lang:'<s:i18n name='forms'><s:text name='forms.locale'></s:text></s:i18n>'});" readonly="readonly"><!-- maxDate:'%y-%M-%d' -->
	  	<font color="red">*</font>
	  	</TD>
	  	<TD class="left" style="text-align:left"></TD>
	  	<TD >
	  	  
	  	</TD>
	  </TR>
	  <TR>
	  	<TD height="26" class="left" style="text-align:left;width:120PX">
		  	<!-- <input type="radio"  id="time1" name="timeID" value="0" checked="checked" onclick="timeFunction1()"/> -->
		  	<s:i18n name="forms"><s:text name="forms.departureTime"></s:text></s:i18n>：
	  	</TD>
	  	<TD>
	  	 <c:if test="${not empty vo.checkbox  }">
		  <input id = "checkboxToSend" type="checkbox" name="vo.checkbox" value="M" <c:if test="${fn:contains(vo.checkbox,'M') }">checked="checked" </c:if> onmousedown="timeCheckBoxFunction()" /><s:i18n name="forms"><s:text name="forms.morning"></s:text></s:i18n>
		  <input type="checkbox" name="vo.checkbox" value="B" <c:if test="${fn:contains(vo.checkbox,'B') }">checked="checked" </c:if> onmousedown="timeCheckBoxFunction()"/><s:i18n name="forms"><s:text name="forms.noon"></s:text></s:i18n>
		  <input type="checkbox" name="vo.checkbox" value="A" <c:if test="${fn:contains(vo.checkbox,'A') }">checked="checked" </c:if> onmousedown="timeCheckBoxFunction()"/><s:i18n name="forms"><s:text name="forms.afternoon"></s:text></s:i18n>
		  <input type="checkbox" name="vo.checkbox" value="N" <c:if test="${fn:contains(vo.checkbox,'N') }">checked="checked" </c:if> onmousedown="timeCheckBoxFunction()"/><s:i18n name="forms"><s:text name="forms.night"></s:text></s:i18n>
		  </c:if>
		  <c:if test="${empty vo.checkbox   }">
		  <input type="checkbox" name="vo.checkbox" value="M" checked="checked"   onmousedown="timeCheckBoxFunction()"/><s:i18n name="forms"><s:text name="forms.morning"></s:text></s:i18n>
		  <input type="checkbox" name="vo.checkbox" value="B" checked="checked"  onmousedown="timeCheckBoxFunction()"/><s:i18n name="forms"><s:text name="forms.noon"></s:text></s:i18n>
		  <input type="checkbox" name="vo.checkbox" value="A" checked="checked"  onmousedown="timeCheckBoxFunction()"/><s:i18n name="forms"><s:text name="forms.afternoon"></s:text></s:i18n>
		  <input type="checkbox" name="vo.checkbox" value="N" checked="checked" onmousedown="timeCheckBoxFunction()"/><s:i18n name="forms"><s:text name="forms.night"></s:text></s:i18n>
		  </c:if>
	  	</TD>
	  	<TD class="left" style="text-align:left;dispay:none;"><!-- <input type="radio" name="timeID" id="time2" value="1" onclick="timeFunction2()"/>自定义： --></TD>
	  	<TD >
	  	</TD>
	  </TR>
	  
	     <TR>

	  	<TD class="left" style="text-align:center;" colspan="4" >
	  	 <input type="button" onclick="javascript:checkJspForm();" value="" class="<s:i18n name='forms'><s:text name='forms.btn01'></s:text></s:i18n>" id="Submit2"/>
	      <input type="reset" onclick=""  value="" class="<s:i18n name='forms'><s:text name='forms.btn02'></s:text></s:i18n>" id="Submit222"/>
	     <!--  <label id="labelFlag">cc</label> -->
	  
	  	</TD>
	  </TR>

	</TABLE>
</form>
<p></p>
<div style="display:none"><input id="text" type="text" value="<s:property value="totalPage"/>"></div>


<div id='priceTable' style="margin:5px 0 0 5px; auto;text-align:left;"></div>
<!-- <div id="crawlrealtime" class="grid-btn-order"  style="float:right; display: block; text-align: right; font-size: 15px;margin-bottom: 5px;">
						<ul>
							<li class="left-normal"></li>
						    <li class="middle-normal" onclick="reloadByCrawlRealTime()">实时获取</li>
							<li class="right-normal"></li>
						</ul>
</div> -->

<br>
<div id="norecord" style="margin-bottom:1px;display:none"><s:text name ="diffprice.searchFail"/></div>

<div class="form_table_tltle"><s:i18n name="forms"><s:text name="forms.queryResults"></s:text></s:i18n></div>
 <!-- <div class="form_down"> -->
 	<table width="0" border="0" cellspacing="0" cellpadding="0"	class="form_list" >
						<tr class="title">
							<td style="text-align: center;width: 38px;" ><s:i18n name="forms"><s:text name="forms.Number"></s:text></s:i18n></td>
							<td style="text-align: center;width: 353px;"><s:i18n name="forms"><s:text name="forms.flight"></s:text></s:i18n></td>
							<td style="text-align: center;width: 85px;"><s:i18n name="forms"><s:text name="forms.flightDate"></s:text></s:i18n></td>
							<td style="text-align: center;width: 115px;"><s:i18n name="forms"><s:text name="forms.grabDate"></s:text></s:i18n></td>
							<td style="text-align: center;width: 80px;"><s:i18n name="forms"><s:text name="forms.highestPrice"></s:text></s:i18n></td>
							<td style="text-align: center;width: 85px;"><s:i18n name="forms"><s:text name="forms.lowestPrice"></s:text></s:i18n></td>
							<td style="text-align: center;width: 50px;"><s:i18n name="forms"><s:text name="forms.tendency"></s:text></s:i18n></td>
							<td style="text-align: center;width: 85px;"><s:i18n name="forms"><s:text name="forms.source"></s:text></s:i18n></td>
							<td style="text-align: center;width: 85px;"><s:i18n name="forms"><s:text name="forms.agent"></s:text></s:i18n></td>
						</tr>
						<tbody id="table2" >
						</tbody>

 </table>
 </div>






<div id="hangduandata" style="display:none;"></div>

<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>

</div>
	<%@ include file="/include/home/home_footer.jsp" %> 
</body>
</html>
<<script type="text/javascript">
<!--

//-->
function timeFunction1(){
	$("#timeFbegin").val("");
	$("#timeTbegin").val("");
	$("[name='vo.checkbox']").attr("checked",true);//全选  
}
function timeCheckBoxFunction(){
	$("input[name=timeID][value=0]").attr("checked",true);
	$("#timeFbegin").val("");
	$("#timeTbegin").val("");
}
function timeFunction2(){
	$("input[name=timeID][value=1]").attr("checked",true);
	 $("[name='vo.checkbox']").removeAttr("checked");//取消全选  
	
}
</script>
<style>
<!--
.l-grid-hd-cell-text{
text-align: center;
cursor:text;
}
-->
</style>
